#!/bin/bash

cat << EOF
**************************************
*       Welcome 常用软件安装         *
*       Author: 周茂恩               *
**************************************
EOF

filepath=$(cd "$(dirname "$0")"; pwd)
index=-1


workDir="/ubuntuAutoScript"
sudo mkdir ${workDir}

function show_menus() {
cat << EOF
[100] Show Menus.
[1] 测试全部.
[0] 退出.
EOF
}


######################### 安装基础软件   ######################### 

# 安装openssh
function openssh() {
	sudo apt-get install openssh-server
	sudo /etc/init.d/ssh restart
}

# 查看ip地址
function nettools() {
	sudo apt install net-tools
}

# 安装sdkman
function sdkman() {
	sudo apt-get install curl
	sudo apt-get install zip
	sudo apt-get install unzip
	curl -s "https://get.sdkman.io" | bash
	source ~/.sdkman/bin/sdkman-init.sh
}

# 安装zerotier
function zerotier() {
	sudo apt-get install curl
	sudo curl -s https://install.zerotier.com | sudo bash
	sudo zerotier-cli join a84ac5c10a09fd21
}

# 安装sublime text3
# 安装微信
# 安装System Monitor
# 安装网易云音乐
# 安装WPS
# 安装docker
# 安装rancher
# rsync 配置
### 更换阿里源并更新系统


# 安装基本软件
function base_tools() {
	openssh
	nettools
	sdkman
	zerotier
}

# 安装typora
function typora() {
	echo "安装typora"
	sudo add-apt-repository 'deb https://typora.io linux/'
	sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA300B7755AFCFAE
	sudo apt update
	sudo apt install typora
}

# 安装谷歌浏览器
function chrome() {
	echo "安装谷歌浏览器"
	if [ ! -f "./google-chrome-stable_current_amd64.deb" ]; then
		echo "不存在google-chrome-stable_current_amd64.deb"
		echo "开始下载google-chrome-stable_current_amd64.deb"
		wget -c "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" -O "google-chrome-stable_current_amd64.deb"
		sudo dpkg -i google-chrome-stable_current_amd64.deb
		sudo apt -f -y install
	else
		sudo dpkg -i google-chrome-stable_current_amd64.deb
		sudo apt -f -y install
	fi
}

# 安装搜狗输入法
function sogoupinyin() {
	echo "安装搜狗拼音"
	if [ ! -f "./sogoupinyin_amd64.deb"]; then
		echo "不存在sogoupinyin_amd64.deb"
		echo "开始下载sogoupinyin_amd64.deb"
		wget -c "https://pinyin.sogou.com/linux/download.php?f=linux&bit=64" -O "sogoupinyin_amd64.deb"
		echo "开始安装sogoupinyin_amd64.deb"
		sudo dpkg -i sogoupinyin_amd64.deb
		sudo apt -f -y install
		sudo dpkg -i sogoupinyin_amd64.deb
	else
		echo "开始安装sogoupinyin_amd64.deb"
		sudo dpkg -i sogoupinyin_amd64.deb
		sudo apt -f -y install
		sudo dpkg -i sogoupinyin_amd64.deb
	fi
}

# 安装网易云音乐
function neteasemusic() {
	if [ ! -f "./netease-cloud-music_amd64_ubuntu.deb" ]; then
		echo "不存在netease-cloud-music_amd64_ubuntu.deb"
		echo "开始下载netease-cloud-music_amd64_ubuntu.deb"
		wget -c "http://d1.music.126.net/dmusic/netease-cloud-music_1.1.0_amd64_ubuntu.deb" -O "netease-cloud-music_amd64_ubuntu.deb"
		echo "开始安装netease-cloud-music_amd64_ubuntu.deb"
		sudo dpkg -i netease-cloud-music_amd64_ubuntu.deb
		sudo apt-get -f install
		sudo dpkg -i netease-cloud-music_amd64_ubuntu.deb
	else
		echo "开始安装netease-cloud-music_amd64_ubuntu.deb"
		sudo dpkg -i netease-cloud-music_amd64_ubuntu.deb
		sudo apt-get -f install
		sudo dpkg -i netease-cloud-music_amd64_ubuntu.deb
	fi
}

# 安装WPS
function wps() {
	if [ ! -f "./wps-office_amd64.deb" ]; then
		echo "不存在wps-office_amd64.deb"
		echo "开始下载wps-office_amd64.deb"
		wget -c "http://kdl.cc.ksosoft.com/wps-community/download/a21/wps-office_10.1.0.5672~a21_amd64.deb" -O "wps-office_amd64.deb"
		echo "开始安装wps-office_amd64.deb"
		sudo dpkg -i wps-office_amd64.deb
		unzip -d ./temp/ wps_symbol_fonts.zip
		cd temp
		sudo cp mtextra.ttf  symbol.ttf  WEBDINGS.TTF  wingding.ttf  WINGDNG2.ttf  WINGDNG3.ttf  /usr/share/fonts
	else
		echo "开始安装wps-office_amd64.deb"
		sudo dpkg -i wps-office_amd64.deb
		unzip -d ./temp/ wps_symbol_fonts.zip
		cd temp
		sudo cp mtextra.ttf  symbol.ttf  WEBDINGS.TTF  wingding.ttf  WINGDNG2.ttf  WINGDNG3.ttf  /usr/share/fonts
	fi
}

# 安装git
function installgit() {
	echo "安装git..."
	sudo apt -y install git
	sudo apt autoremove
}


# 更新系统
function update() {
	sudo apt-get update -y
	sudo apt-get upgrade -y
}

# 卸载不用的软件
function uninstall() {
	echo "卸载libreOffice"
	sudo apt-get remove libreoffice-common
	echo "卸载Amazon"
	sudo apt-get remove unity-webapps-common
	sudo apt autoremove
}

# 下载常用软件
function download() {
	wget -c "https://pinyin.sogou.com/linux/download.php?f=linux&bit=64" -O "sogoupinyin_amd64.deb"
	wget -c "http://d1.music.126.net/dmusic/netease-cloud-music_1.1.0_amd64_ubuntu.deb" -O "netease-cloud-music_amd64_ubuntu.deb"
	wget -c "http://kdl.cc.ksosoft.com/wps-community/download/a21/wps-office_10.1.0.5672~a21_amd64.deb" -O "wps-office_amd64.deb"
	wget -c "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" -O "google-chrome-stable_current_amd64.deb"
}

# 测试全部
function test_all() {
	base_tools

}


show_menus
while(($index!=0))
do
  read -p 'Please input index:' index	
  if [ -z "$index" ];then
    index=100
  fi  
  case  $index  in
    100 ) show_menus;;
	1 ) test_all;;	
	2 ) download;;
	
    * ) show_menus;;
  esac
done

cat << EOF
+-------------------------------------------------+
|  感谢使用!                                      |
+-------------------------------------------------+
EOF
